const { ApiController } = require('jax')

class Controller extends ApiController {
  get Model() {
    return this.ctx.model.Model
  }

  // 分类列表
  async index() {
    const { ctx } = this
    const filter = {}

    const returnData = await this.Model.children({
      filter,
      sort: {
        isTop: 'DESC',
        rank: 'ASC',
      },
    })

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }

  // 分类树
  async tree() {
    const { ctx } = this
    const filter = {}

    const returnData = await this.Model.tree({
      filter,
      sort: {
        isTop: 'DESC',
        rank: 'ASC',
      },
    })

    ctx.body = {
      code: 0,
      msg: 'success',
      data: returnData,
    }
  }
}

module.exports = Controller
